[.mosg {HyRiM} | R Documentation |
Extract or replace parts of a game's payoff matrix
Description
Construct a new game by taking out a specified set of rows, columns and goals from a given game G
. The new game inherits all descriptions (rows, cols and goals) from the G
, and has its list of loss distributions organized in the same way (by rows or columns) as G
.
The extraction or substitution works like as for data frames (see [.data.frame
).
Strategies for both players, as well as goals, can equivalently be addressed by their string-names.
Usage
## S3 method for class 'mosg'
x[i,j,k=NULL]
## S3 replacement method for class 'mosg'
x[i,j,k=NULL] <- value
Arguments
x |
a game of class mosg |
i , j , k |
a numeric value or numeric vector of row incides |
value |
a list of lossDistribution objects, or a game object of class |
Details
For [
extraction of elements from a payoff matrix, omitting any index dimension selects all elements in the respective dimension. Supplying negative values excludes the respective elements. For example, G[c(1:3),1]
returns a game with only the rows 1..3 of G
, but all column strategies that G
had, and only the first of G
's goals retained.
For [<-
, the list of substitute values needs to be of the same length as the number of elements addressed by the triple (i,j,k)
, otherwise an error is returned. If the new elements come from another game object, say G2
, only the loss distributions get replaced, but not the names of the strategies. The replacement checks if G2
has its list of loss distributions organized in the same way as G
, i.e., row-by-row or column-by-column. If there is a mismatch, the substitution is nonetheless done, but a warning about this issue is printed.
Value
[
returns a freshly constructed game object.
Warning
For [<-
, be aware that the replacement does not semantically check if the newly incoming loss distributions make sense as elements of the new game (e.g., they can have different supports, or be discrete/continuous while the game was continuous/discrete in its payoffs). Respective errors may only subsequently come up when the modified or extracted game is used.
Author(s)
Stefan Rass
See Also
Examples
## raw data (PURELY ARTIFICIAL, for demo purposes only)
obs111<-c(rep(1,40),rep(3,20),rep(5,10),rep(7,20),rep(9,10));
obs112<-c(rep(1,50),rep(2,10),rep(4,10),rep(6,20),rep(8,10));
obs121<-c(rep(1,20),rep(4,30),rep(6,20),rep(8,10),rep(10,20));
obs122<-c(rep(1,40),rep(2.5,20),rep(5,20),rep(7.5,10),rep(9,10));
obs211<-c(rep(1,30),rep(2,30),rep(5,10),rep(8,10),rep(10,20));
obs212<-c(rep(1,10),rep(2,10),rep(4,20),rep(7,20),rep(10,40));
obs221<-c(rep(1,30),rep(3,30),rep(4,10),rep(7,20),rep(9,10));
obs222<-c(rep(1,10),rep(3,10),rep(5,50),rep(8,20),rep(10,10));
obs311<-c(rep(1,40),rep(2,30),rep(4,10),rep(7,10),rep(9,10));
obs312<-c(rep(1,20),rep(3,20),rep(4,20),rep(7,20),rep(10,20));
obs321<-c(rep(1,10),rep(3,40),rep(4,30),rep(7,10),rep(9,10));
obs322<-c(rep(1,10),rep(4,30),rep(5,30),rep(7,10),rep(10,20));
## compute payoff densities
f111<-lossDistribution(obs111)
f112<-lossDistribution(obs112)
f121<-lossDistribution(obs121)
f122<-lossDistribution(obs122)
f211<-lossDistribution(obs211)
f212<-lossDistribution(obs212)
f221<-lossDistribution(obs221)
f222<-lossDistribution(obs222)
f311<-lossDistribution(obs311)
f312<-lossDistribution(obs312)
f321<-lossDistribution(obs321)
f322<-lossDistribution(obs322)
payoffs<-list(f111,f112,f121, f122,f211,f212,f221,f222, f311,f312,f321,f322)
G <- mosg( n=2,
m=3,
payoffs,
goals=2,
goalDescriptions=c("g1", "g2"),
defensesDescr = c("d1", "d2"),
attacksDescr = c("a1", "a2", "a3"))
# modify the game by subsetting
G[,c(1,2),] # select only the first two strategies
G[,-3,] # exclude the third strategy (equivalent to before)
# replace a 2x2 subgame related to the second goal
# (replacement data is chosen arbitrarily here)
G2 <- mosg(n=2, m=2, goals=1, losses = list(f111,f112,f121, f122))
G[,c(1,2),1] <- G2 # replace the subgame
# construct another replacement game that is organized different (by column)
G2 <- mosg(n=2, m=2, goals=1, losses = list(f111,f112,f121, f122), byrow=FALSE)
G[,c(1,2),1] <- G2 # this will issue a warning
# plot a submatrix from the game
plot(G[-2,c(1,2),], goal=2)